<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
        <span aria-hidden="true">&times;</span></button>
    <h4 class="modal-title">通知公告</h4>
</div>
<div class="modal-body">

    <div class="form-horizontal row ">
        <form id="form_data">

            <div id="div_error" class="generalAnnouncement generalNotice trainingNotice"></div>

            <div class="form-group col-sm-11 generalAnnouncement generalNotice trainingNotice">
                <label class="control-label col-sm-4 ">类　　型：</label>
                <div class="col-sm-5">
                    <select class="form-control" name="noticeType" id="select2_noticeType">
                        <option value="generalAnnouncement">一般公告</option>
                        <option value="generalNotice">一般通知</option>
                        <option value="trainingNotice">培训通知</option>
                    </select>
                </div>
            </div>


            <div class="form-group col-sm-11 generalAnnouncement">
                <label class="col-sm-4 control-label">发布对象：</label>
                <div class="col-sm-8 ">
                    <div style="padding-top: 5px;height: auto " class="form-control">
                        <c:forEach items="${roleList}" var="i">
                            <label class="checkbox-inline">
                                <input type="checkbox" name="roles[]" value="${i.id}"/>${i.name}
                            </label>
                        </c:forEach>
                    </div>
                </div>

            </div>


            <div class="form-group col-sm-11  generalNotice trainingNotice">
                <label class="col-sm-4 control-label">发布对象：</label>
                <div class="col-sm-5">
                    <div class="input-group">
                        <input type="file" class="form-control  " accept=".xls"
                               id="ExpertFile" name="expertFile">
                                                 <span class="input-group-addon"> <a
                                                         href="<%=request.getContextPath() %>/downloadFileByPath?pathName=excelTemplate/trainTemplate.xls&newName=专家公告（培训）导入模板.xls"><span
                                                         class="glyphicon glyphicon-cloud-download"></span>模板</a>
                                                  </span>
                    </div>
                </div>

            </div>


            <div class="form-group col-sm-11 generalAnnouncement generalNotice trainingNotice">
                <label class="control-label col-sm-4 ">标　　题：</label>
                <div class="col-sm-5">
                    <input type="text" class="form-control" name="name">
                </div>
            </div>


            <div class="form-group col-sm-11  generalAnnouncement generalNotice trainingNotice">
                <label class="control-label col-sm-4 ">内　　容：</label>
                <div class="col-sm-8">
                    <textarea style="height: auto" class="form-control" name="content" cols=40 rows=5></textarea>
                </div>
            </div>


            <div class="form-group col-sm-11 trainingNotice">
                <label class="col-sm-4 control-label">开始时间：</label>
                <div class="col-sm-5">
                    <div class="input-group date form_date timeInput1" style="">
                                                <span class="input-group-addon"><span
                                                        class="glyphicon glyphicon-calendar"></span></span>
                        <input class="form-control " type="text" name="startTime" readonly>
                    </div>
                </div>
            </div>

            <div class="form-group col-sm-11  trainingNotice">
                <label class="col-sm-4 control-label">结束时间：</label>
                <div class="col-sm-5">
                    <div class="input-group date form_date timeInput1">
                                                <span class="input-group-addon"><span
                                                        class="glyphicon glyphicon-calendar"></span></span>
                        <input class="form-control " type="text" name="endTime" readonly>
                    </div>
                </div>
            </div>

            <div class="form-group col-sm-11   trainingNotice">
                <label class="control-label col-sm-4 ">地　　址：</label>
                <div class="col-sm-5">
                    <input type="text" class="form-control  " name="address">
                </div>
            </div>

            <div class="form-group col-sm-11  generalAnnouncement generalNotice trainingNotice">
                <label class="control-label col-sm-4 ">附　　件：</label>
                <div class="col-sm-5">
                    <input type="file" class="form-control  " name="extendFile"
                    >
                </div>
            </div>


            <div class="form-group col-sm-11 generalAnnouncement generalNotice trainingNotice">
                <div class="col-sm-8 col-sm-offset-4">
                    <button type="submit"
                            class="btn btn-default btn-success"><span
                            class="glyphicon glyphicon-ok"></span>&nbsp;确&nbsp;定&nbsp;
                    </button>
                </div>
            </div>
        </form>
    </div>

</div>

<script>
    var $form_data = $("#form_data"), $select2_noticeType = $("#select2_noticeType");
    function changeNoticeType() {
        var noticeType = $("#select2_noticeType").val();
        $form_data.children(":not(." + noticeType + ")").hide();
        $form_data.children("." + noticeType).show();


        $.each($form_data.find('input,textarea'), function () {
            $(this).val(this.defaultValue);
        });


    }
    $(function () {
//        $.sysPlugin.initDateTimeInput();





        $.sysPlugin.initSimpleSelect2();

        $select2_noticeType.on("select2:select", function () {
            changeNoticeType();
            $form_data.data('bootstrapValidator').resetForm();

        });
        changeNoticeType();


        $('.timeInput1').datetimepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd hh:ii',
            weekStart: 1,
            todayBtn: 1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            minView: 0,
            todayHighlight: true,
            forceParse: 0
        }).on("changeDate", function (ev) {
            try {
                var var_filed = $(this).find("input").attr("name");
                $(this).parents("form").bootstrapValidator('revalidateField', var_filed);
            } catch (e) {
            }
        })


    });
</script>

<script>


    <%--bootstrapValidator--%>
    $form_data.bootstrapValidator({
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            noticeType: {
                validators: {
                    notEmpty: {
                        message: '不能为空！'
                    }
                }
            },
            name: {
                validators: {
                    notEmpty: {
                        message: '不能为空！'
                    }
                }
            },
            'roles[]': {
                validators: {
                    notEmpty: {
                        message: '不能为空！'
                    }, number: {}
                }
            },
            expertFile: {
                validators: {
                    notEmpty: {
                        message: '不能为空！'
                    }, number: {}
                }
            },
            content: {
                validators: {
                    notEmpty: {
                        message: '不能为空！'
                    }, number: {}
                }
            },
            address: {
                validators: {
                    notEmpty: {
                        message: '不能为空！'
                    }, number: {}
                }
            },
            startTime: {
                validators: {
                    notEmpty: {
                        message: '不能为空！'
                    }, number: {}
                }
            },
            endTime: {
                validators: {
                    notEmpty: {
                        message: '不能为空！'
                    }, number: {}
                }
            },

        }
    }).on('success.form.bv', function (e) {
        e.preventDefault();
        $.sysPlugin.superAjax({
            data: new FormData($(e.target)[0]),
            contentFile:true,
//            data:$(e.target).serialize(),
            url: '${url}',
            operateType: '${operateType}',
            showSuccessAlert: true,
            showWarnAlert: false,
            successCall: function (data) {
                $.sysPlugin.successCallBack(data, {
                    modal: $("#modal_ajax"),
                    table: $("#table_data")
                })
            },
            errorCall: function (data) {
                $.sysPlugin.errorCallBack(data, {
                    errorAddress: $("#div_error"),
                    form: $form_data
                })
            }
        });
    });


</script>
